package com.jsz.peini.server.thread;

import java.util.LinkedHashMap;
import java.util.TimerTask;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.jsz.peini.bean.task.TaskInfo;
import com.jsz.peini.common.util.SpringContextUtil;
import com.jsz.peini.mapper.task.TaskInfoMapper;
import com.jsz.peini.service.task.TaskInfoService;

public class taskTimertask {
	private static final Logger logger = LoggerFactory.getLogger(taskTimertask.class);
	private String userId;
	private Integer taskId;
	private Integer type;
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public Integer getTaskId() {
		return taskId;
	}
	public void setTaskId(Integer taskId) {
		this.taskId = taskId;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	@Resource
	private TaskInfoMapper taskInfoMapper;
	@Autowired
	private TaskInfoService taskInfoService;
	public void taskend() {
		new java.util.Timer().schedule(new TimerTask() {
			@Override
			public void run() {
				taskInfoMapper = (TaskInfoMapper)SpringContextUtil.getBean(TaskInfoMapper.class);
				taskInfoService = (TaskInfoService)SpringContextUtil.getBean(TaskInfoService.class);
				try {
					Integer endtype=null;
					LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
					TaskInfo taskInfo = taskInfoMapper.selectByPrimaryKey(taskId);
					if (!taskInfo.getOtherUserId().isEmpty()) {
						endtype=2;
					}else {
						endtype=1;
					}
					infoMap=taskInfoService.cancelTaskInfo_refuse(taskInfo,userId,taskId,type,endtype);
				}catch(Exception e){
					logger.error(e.getMessage(),e);
				}
			}
		}, 1000 * 60*60*24);
	}
}
